/*
 * @description: 
 * @Author: latiao
 * @Date: 2021-11-18 16:10:21
 * @LastEditors: latiao
 * @LastEditTime: 2021-11-18 17:33:12
 */
import { getWithdrawalList } from "@/api/modules/finance";
import groupBy from "lodash/groupBy";
import {
  Component,
  Vue
} from "vue-property-decorator";
interface Query{
  accountType:string;
  current:number;
  size:number;
  keyword:string;
  userId:string;
  type:string;
}
@Component({})
export default class withdrawals extends Vue {
  query:Query={
    // 0->团长; 1->区域团长;2->提货点
    accountType: "USER",
    current: 1,
    size: 10,
    keyword: "",
    // 对应用户id
    userId: "",
    // 0->全部记录；1->到账记录
    type: "0",
  }
  isLast:boolean=false

  group:any={}
      /** 提现列表 */
  list:any=[]
  /** 触底加载更多 */
  onReachBottom() {
    this.setData({ "query.current": ++this.query.current });
    this.getWithdrawalList();
  }
  getWithdrawalList(query = {}, refresh = false) {
    /** 如果已为最后一条记录，跳过请求 */
    if (this.isLast && !refresh) {
      return;
    }
    getWithdrawalList({
      ...this.query,
      ...query,
    })
      .then(res => {
        const { current, pages, list } = res;
        // 年-月分组
        const group = groupBy(
          (current > 1 && !refresh ? [...this.list, ...list] : list).map(
            item => {
              const [date, time] = item.createTime.split(" ");
              const [hour, min] = time.split(":");
              const [year, month, day] = date.split("-");
              // const time = item.createTime.slice(6, 16);
              item.groupTime = `${year}-${month}`;
              item.time = `${month}-${day} ${hour}:${min}`;
              return item;
            },
          ),
          item => {
            return [item.groupTime];
          },
        );
       
        /** 如果为最后一页设置到底状态 */
        if (current === pages) {
          this.setData({ isLast: true });
        }

        this.setData({
          group,
          list,
        });
        console.log('group',this.group['2021-07'])
        console.log('list',this.list)
      })
      .catch(err => {
        this.$Popup.toast(err || "佣金数据获取失败");
      });
  }
}
